home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / psion / opaskel3.opl < prev    next >
Text File  |  1995-03-31  |  18KB  |  904 lines

  1.  
  2. REM Skeleton OPA Type 3 Application 
  3. REM 
  4. REM FOR SERIES 3 AND SERIES 3A 
  5. REM -------------------------- 
  6. REM  
  7. REM This program is designed to be a 
  8. REM starting point for you to develop 
  9. REM your own applications. 
  10. REM 
  11. REM Translate it, and play with it. 
  12. REM 
  13. REM It does nothing. (except as 
  14. REM an example, it displays `Data' 
  15. REM files.) 
  16. REM 
  17. REM It contains the system message 
  18. REM processing that all type 3 
  19. REM applications require. Just add in 
  20. REM your functionality, and remove 
  21. REM surplus items (timers etc.) 
  22. REM Use `Outline' mode in the program 
  23. REM editor to get an overview. 
  24. REM 
  25. REM NOTE: The `File' menu 
  26. REM IS IN COMPLETE WORKING ORDER 
  27. REM (for OPL type data files *only*) 
  28. REM 
  29. REM Status Window (Control-Menu) 
  30. REM also fully operational (3a too) 
  31. REM 
  32. REM This code could be streamlined 
  33. REM much more. Particularly, I feel 
  34. REM that the `File' menu choices need 
  35. REM extra layering, as they are so 
  36. REM similar to each other. 
  37. REM  
  38. REM If you have got any other 
  39. REM suggestions, or bug-reports, then 
  40. REM please email me, jezar@cix 
  41. REM 
  42. REM Freely distributable, so; 
  43. REM NO WARRANTIES GIVEN 
  44. REM---------------------------------- 
  45.  
  46.  
  47. REM---------------------------------- 
  48. REM 
  49. REM The APP name is the one that will 
  50. REM appear under the icon in the  
  51. REM `System' screen. It does *not*  
  52. REM have to be the same as the  
  53. REM filename. 
  54.  
  55. APP OpaSkel3 
  56.     REM Put icons etc. here too. 
  57.     TYPE $1003  
  58.      
  59.     PATH "\SKL" 
  60.     EXT  "SKL" 
  61.     REM Change the above to anything. 
  62.     REM but also the global `basenam$' 
  63. ENDA 
  64. REM---------------------------------- 
  65.  
  66.  
  67. REM---------------------------------- 
  68.  
  69. PROC startup%:         REM Startup 
  70.     GLOBAL init$(7,7),exit$(3,7),exit% 
  71.     LOCAL i% 
  72.     REM Link all PROCs with GLOBALs 
  73.     i%=i%+1 :init$(i%)="initgen" 
  74.     i%=i%+1 :init$(i%)="inimenu" 
  75.     i%=i%+1 :init$(i%)="inidisp" 
  76.     i%=i%+1 :init$(i%)="initime" 
  77.     i%=i%+1 :init$(i%)="inifile" 
  78.     i%=i%+1 :init$(i%)="main" 
  79.     @%(init$(1)):(1) 
  80.     RAISE -20 
  81. ENDP 
  82.  
  83.  
  84. PROC cleanup%:(er1%)   REM Cleanup 
  85.     LOCAL er2% 
  86.     REM Run any `cleanup' routines. 
  87.     WHILE exit% 
  88.         er2%=@%(exit$(exit%)): 
  89.         exit%=exit%-1 
  90.     ENDWH 
  91.      
  92.     IF er1% 
  93.         RAISE er1% 
  94.     ELSEIF er2% 
  95.         RAISE er2% 
  96.     ENDIF 
  97.      
  98.     STOP 
  99. ENDP 
  100. REM---------------------------------- 
  101.  
  102.  
  103. REM---------------------------------- 
  104.  
  105. PROC main%:(this%)     REM Main proc 
  106.     GLOBAL sStat%,sMsCode%,sMsKmod% 
  107.     GLOBAL command$(130) 
  108.      
  109.     REM Register our cleanup routine: 
  110.     exit%=exit%+1 :exit$(exit%)="xitmain" 
  111.      
  112.     REM Call asynchronous GETEVENT 
  113.     IOA(-2,14,sStat%,sMsCode%,#0) 
  114.      
  115.     REM Main loop - runs *forever* 
  116.     WHILE 1 
  117.         IOWAIT 
  118.         REM What event has happened? 
  119.          
  120.         REM Timer 1 ? 
  121.         IF tstat1%=0 
  122.             testim1%: 
  123.          
  124.         REM Timer 2 ? 
  125.         ELSEIF tstat2%=0 
  126.             testim2%: 
  127.              
  128.         REM Key or System event ? 
  129.         ELSEIF sStat%<>-46 
  130.             LOCK ON REM (block messages) 
  131.             testmsg%: 
  132.             LOCK OFF 
  133.         ENDIF 
  134.          
  135.     ENDWH 
  136.     REM Code NEVER gets here.. 
  137. ENDP 
  138.  
  139.  
  140. PROC testmsg%: 
  141.     REM For performance reasons, 
  142.     REM embed this code in main%: 
  143.     REM I've seperated for clarity. 
  144.      
  145.     REM Error? (unlikely) 
  146.     IF sStat%<0 
  147.         cleanup:(sStat%) 
  148.     ENDIF 
  149.      
  150.     REM Message from System screen: 
  151.     IF sMsCode%=$0404 
  152.         command$=GETCMD$ 
  153.         FileMngr:(LEFT$(command$,1),MID$(command$,2,130),1) 
  154.         timlive%: 
  155.          
  156.     REM Help key pressed: 
  157.     ELSEIF sMsCode%=$0123 
  158.         Help%: 
  159.      
  160.     REM Psion-letter hotkey: 
  161.     ELSEIF (sMsKmod% AND $08) 
  162.         DoMenu:(sMsCode%) 
  163.          
  164.     REM Menu key: 
  165.     ELSEIF sMsCode%=$0122 
  166.         REM With CTRL key? 
  167.         IF sMsKmod% AND $04 
  168.             togstat%: REM Status window 
  169.         ELSE 
  170.             showmen%: REM Menu display 
  171.         ENDIF 
  172.      
  173.     REM `Enter' key pressed 
  174.     ELSEIF sMsCode%=13 
  175.          
  176.         REM With SHIFT key? 
  177.         IF sMsKmod% AND 2 
  178.             IF POS<>1 
  179.                 BACK 
  180.                 redisp%: REM Show item. 
  181.                  
  182.             ELSE REM  Hit top of file. 
  183.                 gIPRINT "First entry" 
  184.                 BEEP 5,400 
  185.             ENDIF 
  186.              
  187.         REM ..or unshifted: 
  188.         ELSE 
  189.             NEXT  
  190.             IF EOF REM Hit *end* of file. 
  191.                 BACK REM (so skip back) 
  192.                 gIPRINT "No more entries" 
  193.                 BEEP 5,400 
  194.                  
  195.             ELSE   REM Show next entry. 
  196.                 redisp%: 
  197.             ENDIF 
  198.         ENDIF 
  199.      
  200.     REM Program to back (app. key) 
  201.     ELSEIF sMsCode%=$402 
  202.         REM Stop pointless activity: 
  203.         timdead%: 
  204.      
  205.     REM   Prog to front (app. key) 
  206.     ELSEIF sMsCode%=$401 
  207.         REM In view again, start timers: 
  208.         timlive%: 
  209.      
  210.     REM Other (unused) special message: 
  211.     ELSEIF sMsCode% AND $400 
  212.         PRINT "System message: $",HEX$(sMsCode%) 
  213.         BEEP 5,500 
  214.      
  215.     REM Special (non-ASCII) keypress: 
  216.     ELSEIF sMsCode% AND $FF00 
  217.         PRINT "Special key:    $",HEX$(sMsCode%) 
  218.         BEEP 5,500 
  219.          
  220.     REM Normal ASCII keypress 
  221.     ELSE 
  222.         REM Ignore `Tab' etc., for now. 
  223.         IF sMsCode%>=$20 
  224.             PRINT CHR$(sMsCode%); 
  225.         ENDIF 
  226.     ENDIF 
  227.      
  228.     REM Call GETEVENT (next key/event) 
  229.     IOA(-2,14,sStat%,sMsCode%,#0) 
  230. ENDP 
  231.  
  232.  
  233. PROC xitmain%: 
  234.     REM Any cleanup for `main' here. 
  235.     REM mainly just cancelling IOA's 
  236.      
  237.     IF sStat%=-46 
  238.         IOW(-2,4,#0,#0) 
  239.         IOWAITSTAT sStat% 
  240.     ENDIF 
  241. ENDP 
  242. REM------------------------------------ 
  243.  
  244.  
  245. REM------------------------------------ 
  246.  
  247. PROC inifile%:(this%)  REM File cont 
  248.     REM GLOBALs for files. 
  249.     GLOBAL filenam$(130),basenam$(9) 
  250.      
  251.     REM It's a common mistake to think 
  252.     REM That the APP details set the 
  253.     REM following up.  
  254.     REM This isn't true, and usually 
  255.     REM LOADS of problems occur. You  
  256.     REM *must* do it yourself. 
  257.      
  258.     basenam$="\SKL\.SKL" 
  259.      
  260.     REM The above is the only ref to 
  261.     REM any hardcoded path & extension. 
  262.     REM Note NO DRIVE NAME is fixed. 
  263.     REM I think that is the best way. 
  264.      
  265.     REM Link-in file cleanup routine: 
  266.     exit%=exit%+1 :exit$(exit%)="xitfile" 
  267.      
  268.     REM Open file from system screen: 
  269.     FileMngr:(CMD$(3),CMD$(2),1) 
  270.      
  271.     REM Link to next initializer: 
  272.     @%(init$(this%+1)):(this%+1) 
  273. ENDP 
  274.  
  275.  
  276. PROC FileMngr:(command$,file$,showme%) 
  277.     REM This is the file manager. 
  278.     REM It opens/closes data files. 
  279.      
  280.     LOCAL goodnam$(130),o%(6) 
  281.     LOCAL goodpth$(130),here%,show% 
  282.     show%=showme% 
  283.      
  284.     REM Get position in case of error: 
  285.     TRAP USE A :REM (avoid POS error) 
  286.     IF ERR=0 
  287.         here%=POS 
  288.     ENDIF 
  289.      
  290.     REM Close current file (if any) 
  291.     TRAP CLOSE 
  292.      
  293.     REM Set status window name 
  294.     goodnam$=PARSE$(file$,basenam$,o%()) 
  295.     SETNAME goodnam$ 
  296.      
  297.     REM Make path for files 
  298.     goodpth$=MID$(goodnam$,1,o%(4)-1) 
  299.     TRAP MKDIR goodpth$ 
  300.      
  301.     REM If the above failed badly then 
  302.     REM we're in big trouble, but 
  303.     REM `File exists' is OK: 
  304.     IF ERR=0 OR ERR=-32  
  305.          
  306.         REM This isn't used in this APP 
  307.         SETPATH goodpth$ 
  308.          
  309.         IF command$="C" REM Create file 
  310.             REM YOUR FILE FORMAT HERE!: 
  311.             TRAP CREATE goodnam$,A,a1$,a2$,a3$,a4$ 
  312.          
  313.         ELSEIF command$="O" REM Open file 
  314.             REM YOUR FILE FORMAT HERE!: 
  315.             TRAP OPEN goodnam$,A,a1$,a2$,a3$,a4$ 
  316.      
  317.         ELSEIF command$="X" REM Exit 
  318.             cleanup%:(0) 
  319.         ENDIF 
  320.     ENDIF 
  321.      
  322.     REM Re-open previous file if error 
  323.     IF dError%:(0) 
  324.      
  325.         REM ..no previous file! 
  326.         IF filenam$="" 
  327.             cleanup%:(0) 
  328.              
  329.         REM Reopen previous file. 
  330.         ELSE 
  331.             goodnam$=filenam$ 
  332.             filenam$="" 
  333.             FileMngr:("O",goodnam$,0) 
  334.              
  335.             REM Reposition to where we were 
  336.             show%=(here%=0) 
  337.             POSITION here% 
  338.         ENDIF 
  339.          
  340.     REM Success - set global filename. 
  341.     ELSE 
  342.         filenam$=goodnam$ 
  343.     ENDIF 
  344.      
  345.     REM And refresh display 
  346.     IF show% 
  347.         redisp%: 
  348.     ENDIF 
  349. ENDP 
  350.  
  351.  
  352. PROC ChoiceX%: 
  353.     FileMngr:("X","",0) 
  354. ENDP 
  355.  
  356.  
  357. PROC ChoiceO%: 
  358.     REM Open file (dead simple). 
  359.      
  360.     LOCAL newname$(130) 
  361.     newname$=filenam$ 
  362.      
  363.     dINIT "Open file" 
  364.     dFILE newname$,"File:",0 
  365.     IF DIALOG 
  366.         FileMngr:("O",newname$,1) 
  367.     ENDIF 
  368. ENDP 
  369.  
  370.  
  371. PROC ChoiceN%: 
  372.     REM New file (tricky with template) 
  373.      
  374.     LOCAL newname$(130),templ$(130),yt%,o%(6) 
  375.     newname$=filenam$ 
  376.      
  377.     REM Create template path 
  378.     templ$="\wdr\" 
  379.      
  380.     dINIT "Create new file" 
  381.     dFILE newname$,"File:",$11 
  382.     dCHOICE yt%,"Use template","No,Yes" 
  383.     dFILE templ$,"Template:",$21 
  384.     IF DIALOG 
  385.         IF newname$=filenam$ 
  386.             dError%:(-40) 
  387.             RETURN 
  388.         ENDIF 
  389.         BUSY "Creating new file",1,1 
  390.         TRAP DELETE newname$ 
  391.         IF yt%=2 
  392.             TRAP COMPRESS templ$,newname$ 
  393.             IF dError%:(0)=0 
  394.                 FileMngr:("O",newname$,1) 
  395.                 BUSY OFF 
  396.                 RETURN 
  397.             ENDIF 
  398.         ENDIF 
  399.         FileMngr:("C",newname$,1) 
  400.     ENDIF 
  401.     BUSY OFF 
  402. ENDP 
  403.  
  404.  
  405. PROC ChoiceA%: 
  406.     REM Save as <name> (uses copying) 
  407.      
  408.     LOCAL newname$(130),new%,here% 
  409.     newname$=filenam$ 
  410.      
  411.     dINIT "Save as" 
  412.     dFILE newname$,"File:",$11 
  413.     dCHOICE new%,"Use new file","No,Yes" 
  414.      
  415.     IF DIALOG 
  416.         IF newname$=filenam$ 
  417.             dError%:(-40) 
  418.             RETURN 
  419.         ENDIF 
  420.          
  421.         here%=POS 
  422.         TRAP CLOSE 
  423.         IF dError%:(0)=0 
  424.             TRAP DELETE newname$ 
  425.             IF ERR=0 OR ERR=-33 
  426.                 BUSY "Saving",1,1 
  427.                 TRAP COMPRESS filenam$,newname$ 
  428.             ENDIF 
  429.         ENDIF 
  430.          
  431.         IF new%=1 OR dError%:(0) 
  432.             FileMngr:("O",filenam$,0) 
  433.         ELSE 
  434.             FileMngr:("O",newname$,0) 
  435.         ENDIF 
  436.         POSITION here% 
  437.     ENDIF 
  438.     BUSY OFF 
  439. ENDP 
  440.  
  441.  
  442. PROC ChoiceD%: 
  443.     REM Save as template 
  444.      
  445.     LOCAL newname$(130),o%(6),here% 
  446.     newname$=PARSE$("\WDR\",filenam$,o%()) 
  447.      
  448.     dINIT "Save as template" 
  449.     dFILE newname$,"File:",$11 
  450.      
  451.     IF DIALOG 
  452.         IF newname$=filenam$ 
  453.             dError%:(-40) 
  454.             RETURN 
  455.         ENDIF 
  456.          
  457.         here%=POS 
  458.         TRAP CLOSE 
  459.         IF dError%:(0)=0 
  460.             TRAP DELETE newname$ 
  461.             IF ERR=0 OR ERR=-33 
  462.                 BUSY "Saving template",1,1 
  463.                 TRAP COMPRESS filenam$,newname$ 
  464.             ENDIF 
  465.         ENDIF 
  466.          
  467.         FileMngr:("O",filenam$,0) 
  468.         POSITION here% 
  469.     ENDIF 
  470.     BUSY OFF 
  471. ENDP 
  472.  
  473.  
  474. PROC ChoiceM%: 
  475.     REM Merge in 
  476.      
  477.     LOCAL newname$(130),o%(6),here%,fend% 
  478.     fend%=EOF 
  479.     newname$=filenam$ 
  480.      
  481.     dINIT "Merge in" 
  482.     dFILE newname$,"File:",$0 
  483.      
  484.     IF DIALOG 
  485.         IF newname$=filenam$ 
  486.             dError%:(-40) 
  487.             RETURN 
  488.         ENDIF 
  489.          
  490.         here%=POS 
  491.         TRAP CLOSE 
  492.         IF dError%:(0)=0 
  493.             BUSY "Merging",1,1 
  494.             TRAP COMPRESS newname$,filenam$ 
  495.         ENDIF 
  496.          
  497.         FileMngr:("O",filenam$,fend%) 
  498.         POSITION here% 
  499.     ENDIF 
  500.     BUSY OFF 
  501. ENDP 
  502.  
  503.  
  504. PROC ChoiceK%: 
  505.     REM NOTE THAT THE COMPRESS OPTION 
  506.     REM IS NOT RECOMMENDED FOR OPL 
  507.     REM PROGRAMS - ALL DATA FILES 
  508.     REM ARE COMPRESSED AUTOMATICALLY 
  509.     REM ON EXIT (except on Flash) 
  510.     REM 
  511.     REM This routine is provided as 
  512.     REM an example for programs you 
  513.     REM want to keep permanantly open 
  514.     REM and would therefore need such 
  515.     REM an option. 
  516.      
  517.     LOCAL chan%,tmpname$(130),here% 
  518.     tmpname$=filenam$ 
  519.      
  520.     REM Get a unique name: 
  521.     IF IOOPEN(chan%,ADDR(tmpname$),4)=0 
  522.         IOCLOSE(chan%) 
  523.         TRAP DELETE tmpname$ 
  524.         IF dError%:(0) :RETURN :ENDIF 
  525.          
  526.         here%=POS 
  527.         TRAP CLOSE 
  528.         IF dError%:(0) :RETURN :ENDIF 
  529.          
  530.         BUSY "Compressing",1,1 
  531.         TRAP COMPRESS filenam$,tmpname$ 
  532.         IF dError%:(0)=0 
  533.             TRAP DELETE filenam$ 
  534.             IF dError%:(0)=0 
  535.                 TRAP RENAME tmpname$,filenam$ 
  536.                 dError%:(0) 
  537.             ELSE 
  538.                 TRAP DELETE tmpname$ 
  539.             ENDIF 
  540.         ELSE 
  541.             TRAP DELETE tmpname$ 
  542.         ENDIF 
  543.         FileMngr:("O",filenam$,0) 
  544.         POSITION here% 
  545.     ENDIF 
  546.     BUSY OFF 
  547. ENDP 
  548.  
  549.  
  550. PROC xitfile%: 
  551.     REM Any file-system related cleanup here 
  552.     TRAP CLOSE 
  553. ENDP 
  554.  
  555.  
  556.  
  557. REM----------------------------------------- 
  558. PROC help%:            REM Dialogs 
  559.     LOCAL choose% 
  560.      
  561.     REM Your help here (naturally :-) 
  562.     dINIT 
  563.         dTEXT "","Help: OPA Skeleton V3.21",$302 
  564.         dTEXT "","bItem 1",$500 
  565.         dTEXT "","bItem 2",$500 
  566.         dTEXT "","bItem 3",$500 
  567.     choose%=DIALOG 
  568.      
  569.     REM You would typically VECTOR on 
  570.     REM the choose% variable here for 
  571.     REM further `help' items. 
  572. ENDP 
  573.  
  574.  
  575. PROC dError%:(error%) 
  576.     REM User error notification of error 
  577.     LOCAL errno% 
  578.      
  579.     IF error% 
  580.         errno%=error% 
  581.     ELSE 
  582.         errno%=ERR 
  583.     ENDIF 
  584.      
  585.     IF errno% 
  586.         dINIT ERR$(errno%) 
  587.             dBUTTONS "Continue",-27 
  588.         DIALOG 
  589.         RETURN errno% 
  590.     ENDIF 
  591. ENDP 
  592.  
  593.  
  594.  
  595. REM----------------------------------------- 
  596. PROC inimenu%:(this%)  REM Menus 
  597.     REM GLOBALs for menu 
  598.     GLOBAL mFixP1&(7),mFixP2&(7),mdata&(8) 
  599.     GLOBAL menuops$(10) 
  600.      
  601.     REM Allowable menu hot-keys: 
  602.     menuops$="NOAMKDX" 
  603.      
  604.     REM Initialise MENU Series 3 bug-fix 
  605.     REM Not needed on 3a, but harmless if run. 
  606.     mFixP1&(1)=&8BF88BFC :mFixP1&(2)=&8B00121E 
  607.     mFixP1&(3)=&778B205F :mFixP1&(4)=&E42AAC0C 
  608.     mFixP1&(5)=&A5ABC88B :mFixP1&(6)=&75C084AC 
  609.     mFixP1&(7)=&CBF8E2FB :mFixP2&(1)=&00B4F08B 
  610.     mFixP2&(2)=&FC808BCD :mFixP2&(3)=&AD0D7330 
  611.     mFixP2&(4)=&C932D08B :mFixP2&(5)=&CDD88BAD 
  612.     mFixP2&(6)=&F8754ACF :mFixP2&(7)=&CB 
  613.      
  614.     @%(init$(this%+1)):(this%+1) 
  615. ENDP 
  616.  
  617. PROC showmen%: 
  618.     LOCAL keycode% 
  619.      
  620.     mINIT 
  621.         mCARD "File","New file",%n,"Open file",%o,"Save as",%a,"Merge in",%m,"Compress",%k,"Save as template",%d 
  622.         mCARD "Special","Exit",%x 
  623.          
  624.     REM This machine code is to fix a ROM bug: 
  625.     USR(ADDR(mFixP1&(1)),ADDR(mData&(1)),0,0,0) 
  626.         keycode%=MENU 
  627.     USR(ADDR(mFixP2&(1)),ADDR(mData&(1)),0,0,0) 
  628.          
  629.     DoMenu:(keycode%) 
  630. ENDP 
  631.  
  632.  
  633. PROC DoMenu:(keycode%) 
  634.     LOCAL k$(1) 
  635.      
  636.     k$=CHR$(keycode% AND $DF) 
  637.     IF LOC(menuops$,k$) 
  638.         @%("Choice"+k$): 
  639.     ENDIF 
  640. ENDP 
  641.  
  642.  
  643.  
  644. REM----------------------------------------- 
  645. PROC initgen%:(this%)  REM Other 
  646.     REM Stick ESCAPE OFF in here, but 
  647.     REM *ONLY* when fully debugged. 
  648.      
  649.     REM Prevent this application from 
  650.     REM keeping the machine turned on: 
  651.     CALL ($138b) REM GenMarkNonActive. 
  652.      
  653.     @%(init$(this%+1)):(this%+1) 
  654. ENDP 
  655.  
  656.  
  657. PROC inidisp%:(this%)  REM Displays 
  658.     GLOBAL StWin%,S3a% 
  659.      
  660.     REM This is presumtious I know: 
  661.     S3a%=(gHEIGHT=160 AND gWIDTH=480) 
  662.      
  663.     togstat%: 
  664.     REM For this example only: 
  665.     IF S3a% 
  666.         SCREEN 50,11,2,2 
  667.     ELSE 
  668.         SCREEN 30,7,2,2 
  669.     ENDIF 
  670.     CURSOR ON 
  671.      
  672.     PRINT "Use ENTER and SHIFT-ENTER" 
  673.     PRINT "(existing data files only)" 
  674.     PAUSE -30 
  675.      
  676.     @%(init$(this%+1)):(this%+1) 
  677. ENDP 
  678.  
  679. PROC togstat%: 
  680.     REM Status window toggle. 
  681.     LOCAL x%,y%,w%,h% 
  682.      
  683.     gAT gWIDTH-2,0 
  684.     gFILL 2,gHEIGHT,1 
  685.     IF S3a% 
  686.         REM My bizzare modulo command :-) 
  687.         StWin%=LOC("20",CHR$(StWin%+%0)) 
  688.          
  689.         REM OS version of STATUSWIN x (3a) 
  690.         CALL($6B8D,StWin%) 
  691.          
  692.         REM Get status window size 
  693.         CALL($F08D,-1,0,0,ADDR(x%)) 
  694.          
  695.     ELSE 
  696.         StWin% = NOT StWin% 
  697.         IF StWin%  
  698.             STATUSWIN ON  
  699.             w% = 50 
  700.             x% = 189 
  701.         ELSE 
  702.             STATUSWIN OFF 
  703.             w% = 0 
  704.             x% = 240 
  705.         ENDIF 
  706.     ENDIF 
  707.      
  708.     gSETWIN 0,0,x%,gHEIGHT 
  709.     gAT gWIDTH-2,0 
  710.     gFILL 2,gHEIGHT,1 
  711.     gBORDER 0 
  712.     redisp%: 
  713. ENDP 
  714.  
  715.  
  716. PROC redisp%: 
  717.     REM Screen redrawing goes here. 
  718.      
  719.     TRAP USE A REM Check file is open. 
  720.     IF ERR :RETURN :ENDIF 
  721.     CLS 
  722.     prec%:(A.a1$) 
  723.     prec%:(A.a2$) 
  724.     prec%:(A.a3$) 
  725.     prec%:(A.a4$) 
  726.     PRINT ""; REM Move cursor 
  727. ENDP 
  728.  
  729.  
  730. PROC prec%:(rec$) 
  731.     REM Print out a record, replacing 
  732.     REM line breaks with commas. 
  733.      
  734.     LOCAL nl%,onl%,brk$(255) 
  735.      
  736.     brk$=rec$ 
  737.     onl%=1 
  738.      
  739.     DO 
  740.         IF nl% 
  741.             PRINT ",", 
  742.         ENDIF 
  743.         brk$=MID$(brk$,onl%,254) 
  744.         nl%=LOC(brk$,CHR$(21)) 
  745.         IF nl%=0 
  746.             nl%=255 
  747.         ENDIF 
  748.         PRINT LEFT$(brk$,nl%-1); 
  749.         onl%=nl%+1 
  750.     UNTIL nl%=255 
  751.     PRINT 
  752. ENDP 
  753.  
  754.  
  755. REM----------------------------- 
  756. REM Additional example stuff: 
  757. REM 
  758. REM This next section, is taken from 
  759. REM my "timers" example. It is a 
  760. REM good example of how to slot in a 
  761. REM new code section with globals. 
  762. REM 
  763. REM So.. Basically the only refs 
  764. REM to this code, in ANY of the code  
  765. REM above are: 
  766. REM 
  767. REM initime%: 
  768. REM testim* 
  769. REM timlive%: 
  770. REM timdead%: 
  771. REM 
  772. REM and the two status words tstat* 
  773. REM 
  774. REM You would probably strip this 
  775. REM timer code out in a real app. 
  776. REM (unless you need timers! :-) 
  777.  
  778.  
  779. PROC initime%:(this%)  REM Timer demo 
  780.     GLOBAL tenths1&,tenths2& 
  781.     GLOBAL tchan1%,tchan2% 
  782.     GLOBAL tstat1%,tstat2% 
  783.     GLOBAL tbit%,cid%,tlive% 
  784.     LOCAL width% 
  785.      
  786.     REM remember current bitmap 
  787.     cid%=gIDENTITY 
  788.     width%=gWIDTH 
  789.      
  790.     REM create a new bitmap 
  791.     tbit%=gCREATE(width%-25,10,58,50,1) 
  792.     gBORDER 1 
  793.     gAT 4,14 
  794.     gPRINT "Timers:" 
  795.      
  796.     REM Our timer speeds: 
  797.     tenths1&=5 :tenths2&=7 
  798.      
  799.     REM Open two timer channels: 
  800.     iocheck%:(IOOPEN(tchan1%,"TIM:",-1)) 
  801.     iocheck%:(IOOPEN(tchan2%,"TIM:",-1)) 
  802.      
  803.     REM Start the timers: 
  804.     timlive%: 
  805.      
  806.     REM Switch to original bitmap 
  807.     gUSE cid% 
  808.      
  809.     REM install timer cleanup: 
  810.     exit%=exit%+1 :exit$(exit%)="xittim" 
  811.      
  812.     REM and link to next initiator: 
  813.     @%(init$(this%+1)):(this%+1) 
  814. ENDP 
  815.  
  816.  
  817. PROC testim1%: 
  818.     REM test timer 1 
  819.     LOCAL cid% 
  820.      
  821.     REM remember current window 
  822.     cid%=gIDENTITY 
  823.      
  824.     REM switch to timer bitmap: 
  825.     gUSE tbit% 
  826.      
  827.     REM Render graphics for timer 1: 
  828.     gAT 10,23 
  829.     gINVERT 10,10 
  830.      
  831.     REM We now restart this timer: 
  832.     iocheck%:(IOA(tchan1%,1,tstat1%,tenths1&,#0)) 
  833.      
  834.     REM switch back to original bitmap 
  835.     gUSE cid% 
  836. ENDP 
  837.  
  838.  
  839. PROC testim2%: 
  840.     REM test timer 2 
  841.     LOCAL cid% 
  842.      
  843.     REM remember current window 
  844.     cid%=gIDENTITY 
  845.      
  846.     REM switch to timer bitmap: 
  847.     gUSE tbit% 
  848.      
  849.     REM render timer 2 graphics: 
  850.     gAT 27,19 
  851.     gINVERT 20,20 
  852.      
  853.     REM We now restart this timer: 
  854.     iocheck%:(IOA(tchan2%,1,tstat2%,tenths2&,#0)) 
  855.      
  856.     REM switch back to original bitmap 
  857.     gUSE cid% 
  858. ENDP 
  859.  
  860.  
  861. PROC timlive%: 
  862.     REM start both timers: 
  863.     IF tlive%=0 
  864.         iocheck%:(IOA(tchan1%,1,tstat1%,tenths1&,#0)) 
  865.         iocheck%:(IOA(tchan2%,1,tstat2%,tenths2&,#0)) 
  866.         tlive%=1 
  867.         gIPRINT "Timers started" 
  868.     ENDIF 
  869. ENDP 
  870.  
  871.  
  872. PROC timdead%: 
  873.     REM Kill timers 
  874.     IF tlive% 
  875.         IOW(tchan2%,4,#0,#0) 
  876.         IOWAITSTAT tstat2% 
  877.         IOW(tchan1%,4,#0,#0) 
  878.         IOWAITSTAT tstat1% 
  879.         tlive%=0 
  880.     ENDIF 
  881. ENDP 
  882.  
  883.  
  884. PROC xittim%: 
  885.     REM Cancel everything: 
  886.     timdead%: 
  887.      
  888.     REM ..and close: 
  889.     IOCLOSE(tchan2%) 
  890.     IOCLOSE(tchan1%) 
  891.     gCLOSE(tbit%) 
  892. ENDP 
  893.  
  894. PROC iocheck%:(code%) 
  895.     IF code% 
  896.         cleanup%:(code%) 
  897.     ENDIF 
  898. ENDP 
  899.  
  900.  
  901. REM ---- End of file ---- 
  902.  
  903.  
  904.